<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class ContentController extends Controller{

	//构造函数
	public function __init(){
		
		
	}
	
//  首页展示
    public function content(){
    	
		

			$gid=Q('get.gid',0,'intval');
//			
		
			$gcData=Db::table('cate')->join('goods','cid','=','cate_cid')->where('gid',$gid)->first();
	
//			p($gcData);die;
			View::with('gcData',$gcData);
			$gid=$gcData['gid'];
//			p($gid);die;
	
		
		$specData=Db::table('goods_attr ga')
		->join('type_attr ta','ga.taid','=','ta.taid')
		->where('ta.class',1)
		->where('ga.gid',$gid)
		
		->groupBy('ta.taid')
		->get();
//		p($specData);die;

		foreach($specData as $k=>$v){
			$specData[$k]['son']=Db::table('goods_attr ga')
		->join('type_attr ta','ga.taid','=','ta.taid')
		->where('ta.class',1)
		->where('ga.gid',$gid)
		->where('ta.taid',$v['taid'])
		->get();
			
		}
//		
//		获取商品详情
		$detailData=Db::table('detail')->where('gid',$gid)->first();
		$detailData['photo']=explode(',',$detailData['photo']);
		
//		获取单位
		$goodsData=Db::table('goods')->where('gid',$gid)->first();
		
		View::with('goodsData',$goodsData);
		
//		p($detailData);die;
		View::with('detailData',$detailData);

		
//		p($specData);die;
		View::with('specData',$specData);
		
		
		
       View::make();
    }
	
	
	public function selectsql(){
		$combine=Q('post.combine');
		
		$combine=rtrim($combine,',');
		
		$glModel=new \Common\Model\Glist;
		
		 $glData=$glModel->where('combine',$combine)->find();
		 
		 if($glData['inventory'] == 0){
				echo json_encode(array(
					'nm' => 0,
					'info' => '太热销了，卖空了！补货中'
				));
        }else{
        	echo json_encode(array(
					'nm' => 1,
					'info' =>$glData['inventory']
				));
        }
	}
	
	
	
	
}
